/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package funcenter.db;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author arthur
 */
public class Conexao {
    
    private Connection conn;
    private static Conexao singleton;
 
    private Conexao() {
        File dir = new File("./lib/");
        System.out.println(dir.getPath());
        for(int i = 0; i < dir.listFiles().length; i++){
            System.out.println(dir.listFiles()[i]);                
        }
        try {
            Class.forName("org.hsqldb.jdbc.JDBCDriver");
            conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/funcenter", "sa", "");
        } catch(Exception ex){
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
    public static Conexao getInstance() throws Exception {
        if (singleton == null)
            singleton = new Conexao();
        return singleton;
    }
 
    public Connection getConexao(){
        return conn;
    }
    
    public void fechar(){
        System.out.print("fechou");
        try {
            PreparedStatement ps = conn.prepareStatement("SHUTDOWN");
            ps.execute();
            conn.close();
        } catch(Exception ex){
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}